<?php
// vypis tabulky z dvojrozmeneho pole a soucty radku a sloupcu

$fp = fopen ("table.csv","r");
$row = 0;
while ($data = fgetcsv ($fp, 1000, ";")) {
    if (sizeof($data)) $pole[$row] = $data;
    $row++;
}
fclose ($fp);

$sums = array();
$sumr = array();

if (isset($pole) && sizeof($pole)) {
    echo '<table>';
    foreach ($pole as $cisloradku=>$radek) {
        echo '<tr>';
        foreach ($radek as $cislosloupce=>$sloupec) {
            echo '<td>'.$sloupec.'</td>';
            $sumr[$cisloradku] += $sloupec;
            $sums[$cislosloupce] += $sloupec;
        }
        // vypis sumy radku
        echo '<td>'.$sumr[$cisloradku].'</td>';
        echo '</tr>';
    }
    //vypis sumy sloupcu
    echo '<tr>';
    foreach ($sums as $val) echo '<td>'.$val.'</td>';
    echo '</tr>';
    echo '</table>';
}
?>
